<template>
  <div class="insert-card-wrap" :class="{ 'insert-col-3': colType === 3 }">
    <img
      v-if="insertCardObj.status === 0"
      class="pic-insert-card"
      :src="http2httpsLocal(insertCardObj.imgUrl)"
      alt=""
      @click.stop="handleClick"
    />
    <div v-else class="insert-card-product">
      <div class="title">
        {{ insertCardObj.name || '' }}
      </div>
      <div v-if="productPluginCardList.length > 0" class="recommend-list">
        <div
          v-for="(product, index) in productPluginCardList"
          :key="index"
          class="recommend-item"
          @click="handleItemClick(product, index)"
        >
          <div class="img-wrap-box">
            <img :src="http2httpsLocal(product.productPicUrl)" alt="" />
            <div v-if="product.soldOut" class="sellout">
              售罄
            </div>
          </div>
          <div class="product-des">
            {{ product.productName || '' }}
          </div>
          <div class="price-wrap">
            <div class="price">
              <span class="unit">¥</span><span>{{ product.price }}</span
              ><span class="linePrice">¥{{ product.tagPrice }}</span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { goLink, http2https } from '@/utils/util';

export default {
  name: 'insertCard',
  props: {
    insertCardObj: {
      type: Object,
      default: () => {}
    },
    colType: {
      type: Number,
      default: 1
    },
    mainProperties: {
      type: String,
      default: ''
    },
    conferenceName: {
      type: String,
      default: ''
    },
    tabName: {
      type: String,
      default: ''
    }
  },
  computed: {
    productPluginCardList() {
      return this.insertCardObj.productPluginCardList || [];
    },
    adId() {
      return this.insertCardObj.id || '';
    }
  },
  methods: {
    http2httpsLocal(url) {
      return http2https(url);
    },
    // 纯图片插卡位点击
    handleClick() {
      const { ringshopLinkUrl, activityId, name } = this.insertCardObj || {};
      let { hrefType } = this.insertCardObj || {};
      hrefType = hrefType || 0;
      if (!ringshopLinkUrl) {
        return;
      }
      switch (hrefType) {
        case 0: // 落地页
          goLink(ringshopLinkUrl, (params, path) => {
            this.$router
              .push({
                path,
                query: {
                  ...params,
                  shopId: this.$route.query.shopId
                }
              })
              .catch(err => {
                console.log(err);
              });
          });
          break;
        case 1: // 图片类型
          this.$router.push({
            path: 'banner-image',
            query: {
              name,
              imgUrl: ringshopLinkUrl
            }
          });
          break;
        case 2: // 活动类型
          this.$router.push({
            path: 'brand',
            query: {
              activityNo: ringshopLinkUrl
            }
          });
          break;
        case 3: // 商品类型
          this.$router.push({
            path: 'productDetail',
            query: {
              productId: ringshopLinkUrl,
              shopId: this.$route.query.shopId,
              activityNo: activityId
            }
          });
          break;
        default:
          break;
      }
    },
    // 商品插卡位点击
    handleItemClick(product) {
      this.$router.push({
        path: 'productDetail',
        query: {
          productId: product.productNo,
          shopId: this.$route.query.shopId,
          activityNo: product.activityNo
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.insert-col-3 {
  margin-left: 3px;
  margin-right: 3px;
}
.insert-card-wrap {
  margin-bottom: 10px;
  .pic-insert-card {
    width: 355px;
    height: 114px;
    border-radius: 6px;
    display: inline-block;
  }

  .insert-card-product {
    width: 351px;
    /*height: 196px;*/
    background: #fff;
    border-radius: 6px;
    padding: 12px 0 12px 12px;
    box-sizing: border-box;
  }

  .title {
    font-size: 14px;
    font-family: PingFangSC-Regular;
    color: #333;
    line-height: 20px;
    margin-bottom: 10px;
  }

  .recommend-list {
    width: 100%;
    overflow-x: scroll;
    display: flex;
  }

  .recommend-item {
    width: 98px;
    margin-right: 10px;

    .img-wrap-box {
      position: relative;
      width: 98px;
      height: 98px;
      img {
        width: 98px;
        height: 98px;
        border-radius: 2px;
        display: inline-block;
      }
      .sellout {
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        margin: auto;
        display: flex;
        justify-content: center;
        align-items: center;
        width: 65px;
        height: 65px;
        border-radius: 50%;
        color: #fff;
        font-size: 16px;
        background-color: rgba(0, 0, 0, 0.6);
      }
    }
  }
  .product-des {
    margin-top: 4px;
    width: 98px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: #333;
    font-size: 12px;
  }
  .price-wrap {
    .price {
      font-size: 16px;
      font-family: DINAlternate-Bold, DINAlternate;
      font-weight: bold;
      color: #e40000;
      margin-top: 4px;
      line-height: 20px;
    }
    .unit {
      font-size: 12px;
      margin-right: 2px;
    }
    .linePrice {
      text-decoration: line-through;
      font-size: 11px;
      font-family: PingFangSC-Regular;
      font-weight: normal;
      color: #999;
      line-height: 14px;
      margin-left: 2px;
    }
  }
}
</style>
